<?php

namespace app\admin\model;

use app\admin\common\Constants;

class Seal extends Common
{

    /**
     * 格式化过期时间
     * @return false|string
     */
    public function getExpiredTimeTxtAttr()
    {
        return date('Y-m-d', $this->expired_time);
    }

    public function getStatusTxtAttr()
    {
        $config = new Config();
        $cache = $config->getConfigCacheByName(Constants::$SEAL_STATUS_KEY);
        return $cache[$this->status]['name'];
    }

    public function getSealTypeTxtAttr()
    {
        $config = new Config();
        $cache = $config->getConfigCacheByName(Constants::$SEAL_TYPE_KEY);
        return $cache[$this->seal_type]['name'];
    }

    /**
     *
     * 企业Id预定义查询
     * @param $query
     * @param $companyId
     */
    protected function scopeCompany($query, $companyId)
    {
        $query->where("company_id", $companyId);
    }


    public function appForms()
    {
        return $this->hasMany('AppForm', 'seal_id');
    }

    /**
     * 格式化收到日期
     * @return false|string
     */
    public function getDateReceivedTxtAttr()
    {
        return date('Y-m-d', $this->date_received);
    }

    public function cover()
    {
        return $this->hasOne('Picture', 'id', 'img');
    }

    public function creatorUser()
    {
        return $this->hasOne('User', 'id', 'creator');
    }

    public function updaterUser()
    {
        return $this->hasOne('User', 'id', 'updater');
    }

}